package com.qiaofang.housewarehouse.service.compose;

import com.qiaofang.housewarehouse.dao.domain.HswhInfoIntegrity;
import com.qiaofang.housewarehouse.dao.utils.ArithUtils;
import com.qiaofang.housewarehouse.stub.bean.InfoIntegrityDTO;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;

public class HouseCollectionQualityCompose {
    public static InfoIntegrityDTO composeDeal(List<HswhInfoIntegrity> list){
        InfoIntegrityDTO infoIntegrityDTO=new InfoIntegrityDTO();
        if(CollectionUtils.isEmpty(list)){
            return infoIntegrityDTO;
        }
        Long totalCount = 0L;//总记录数
        Long contactMobileCount = 0L; //联系方式
        Long addressCount = 0L; //地址
        Long estateCount = 0L;
        Long priceCount = 0L;//价钱
        Long roomAreaCount = 0L;//面积
        Long houseTypeCount = 0L;//户型
        Long floorCount = 0L;//楼层
        Long directionCount = 0L; //朝向
        Long decorationCount = 0L; //装修
        Long yearCount = 0L; //年代
        Long createTime = 0L;//时间
        Long descCount = 0L;//房源描述
        for(HswhInfoIntegrity DO:list){
            totalCount  = totalCount + DO.getTotalCount();
            contactMobileCount = contactMobileCount + DO.getContactMobileCount();
            addressCount = addressCount + DO.getAddressCount();
            estateCount = estateCount + DO.getEstateCount();
            priceCount = priceCount + DO.getPriceCount();
            roomAreaCount = roomAreaCount + DO.getRoomAreaCount();
            houseTypeCount = houseTypeCount + DO.getHouseTypeCount();
            floorCount = floorCount + DO.getFloorCount();
            directionCount = directionCount + DO.getDirectionCount();
            decorationCount = decorationCount + DO.getDecorationCount();
            if(null != DO.getYearCount()) {yearCount = yearCount + DO.getYearCount();}
            createTime = createTime + DO.getCreateTime();
            descCount = descCount +DO.getDescCount();
        }
        infoIntegrityDTO.setTotalCount(String.valueOf(totalCount));
        infoIntegrityDTO.setContactMobileCount(String.valueOf(contactMobileCount));
        infoIntegrityDTO.setContactMobileRate(ArithUtils.getPercent(ArithUtils.div(contactMobileCount, totalCount, 4 )));
        infoIntegrityDTO.setAddressRate(ArithUtils.getPercent(ArithUtils.div(addressCount, totalCount, 4 )));
        infoIntegrityDTO.setEstateCountRate(ArithUtils.getPercent(ArithUtils.div(estateCount, totalCount, 4 )));
        infoIntegrityDTO.setPriceRate(ArithUtils.getPercent(ArithUtils.div(priceCount, totalCount, 4 )));
        infoIntegrityDTO.setRoomAreaRate(ArithUtils.getPercent(ArithUtils.div(roomAreaCount, totalCount, 4 )));
        infoIntegrityDTO.setHouseTypeRate(ArithUtils.getPercent(ArithUtils.div(houseTypeCount, totalCount, 4 )));
        infoIntegrityDTO.setFloorRate(ArithUtils.getPercent(ArithUtils.div(floorCount, totalCount, 4 )));
        infoIntegrityDTO.setDirectionRate(ArithUtils.getPercent(ArithUtils.div(directionCount, totalCount, 4 )));
        infoIntegrityDTO.setDecorationRate(ArithUtils.getPercent(ArithUtils.div(decorationCount, totalCount, 4 )));
        if(0L != yearCount){
            infoIntegrityDTO.setYearRate(ArithUtils.getPercent(ArithUtils.div(yearCount, totalCount, 4 )));
        }
        infoIntegrityDTO.setPublishTimeRate(ArithUtils.getPercent(ArithUtils.div(createTime, totalCount, 4 )));
        infoIntegrityDTO.setDescRate(ArithUtils.getPercent(ArithUtils.div(descCount,totalCount, 4 )));
        return infoIntegrityDTO;
    }
}
